package com.putao.album.application;

import android.app.Application;
import android.content.Context;

import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.putao.album.util.AppHelper;
import com.putao.album.util.DisplayHelper;
import com.putao.album.util.UmengPushHelper;
import com.umeng.analytics.MobclickAgent;

public class GlobalApplication extends Application {
    private static Context globalContext;


    @Override
    public void onCreate() {
        super.onCreate();
        globalContext = getApplicationContext();
        DisplayHelper.init(this);
        setImageLoaderConfig();
        setMobclickAgent();
    }

    /**
     * 设置Imageloader配置
     */
    void setImageLoaderConfig() {
        try {
            ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(globalContext)
                    .memoryCacheExtraOptions(DisplayHelper.getScreenWidth(),DisplayHelper.getScreenHeight())
                    .diskCache(new UnlimitedDiskCache(AppHelper.getAlbumDiskCacheDir()))
                    .diskCacheSize(100 * 1024 * 1024)
                    .diskCacheFileCount(100)
                    .build();
            ImageLoader.getInstance().init(config);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 设置统计配置
     */
    void setMobclickAgent() {
        MobclickAgent.openActivityDurationTrack(false);
        MobclickAgent.setDebugMode(false);
        MobclickAgent.setSessionContinueMillis(30 * 1000);
        MobclickAgent.setCatchUncaughtExceptions(true);
    }

    public static Context getInstance() {
        return globalContext;
    }


}
